<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Models\Anote;
use App\Models\huser;
use App\Models\Amodule;
class AnoteController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    //帖子
    public function index(Request $request)
    {   
        $input = $request->input('keywords')?$request->input('keywords'):'';
        //帖子管理
        // $users = User::with('UserInfo')->paginate(3);
        $data = anote::with('huser','amodule')->where('title','like','%'.$input.'%')->orwhere('content','like','%'.$input.'%')->paginate(3);
        // dump($data = $anote->all());
        // dump($data[0]['title']);
        // $user = new user;
        // dump($data = $user->anote()->get());
        // dump($data = $anote->all());
        //dump($data[0]['title']);
        // dump($data[1]->amodule);
        // dd($data);
        return view('admin.anote.index',['data'=>$data,'input'=>$input]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
         $Amodule = new Amodule();
        $data = $Amodule->tree();
        return view('admin.anote.add',['data'=>$data]);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        dump($request->input());
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $data = Anote::find($id);
        $data->content = '该用户违反本论坛协议该帖以删除';
        $data->save();
        if($data){
            return redirect('admin/anote');
        }else{
            return back()->with('msg','修改失败');
        }
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    //ajax删除帖子
    public function destroy(Request $request,$id)
    {
        $data = [];
        $re = Anote::find($id)->delete();
        if($re){
            $data=[
                'status'=>0,
                'msg'=>'删除成功'
            ];
        }else{
            $data=[
                'status'=>1,
                'msg'=>'删除失败'
            ];
        }
        return $data;
    }
}
